window.onload=function (){
 this.getnewalbum();
 this.getSwiper();
}

function  getnewalbum(){
    $ajax({
        url:newalbum,
        method:'get',
        success:function (e){
            // console.log(e);
            let result=e.products;
            const oSectionAlbumList=document.querySelector('.section-album-list');
            let str='';
            result.forEach(item=>{
                 str+=`<li class="section-album-items">
                     <div class="sec-con-box">
                         <a href="" class="section-content-links">
                             <img src="${item.coverUrl}" alt="" class="sec-con-pic">
                         </a>
                     </div>
                     <div class="sec-con-text">
                         <h3 class="sec-con-title">
                             <a href="#" class="sec-con-title-link" title="Proof">${item.albumName}</a>
                         </h3>
                         <p class="start-con-info"><a href="" class="start-con-author">${item.artistName
                 }</a></p>
                         <p class="album-price"><i class="album-price-i">¥ ${item.price}</i> <span
                                 class="album-price-span">立即购买</span></p>
                     </div>
                 </li>`
            })
            oSectionAlbumList.innerHTML=str;
        }
    })
}

/**
 * 获取轮播图
 */
function getSwiper() {
    $ajax({
        url: swiper_url,
        method: 'get',
        success: function (e) {
            console.log(e);
            if (e.code === 200) {
                // 拿到轮播图片
                let swiperWrapper = document.getElementById('swiper-wrapper')
                let data = e.banners
                let str = ''
                data.forEach(item => {
                    str += `<div class="swiper-slide">
                    <a href="" class="ticket-banner-a">
                        <img src="${item.imageUrl}" alt="" class="ticket-banner-pic">
                    </a>
                </div>`
                })
                swiperWrapper.innerHTML = str
                // 在数据请求成功之后初始化轮播图 否则会出现无法轮播的情况
                new Swiper('.swiper', {
                    loop: true, // 循环模式选项
                    autoplay: true,
                    // 如果需要分页器
                    pagination: {
                        el: '.swiper-pagination',
                    },
                    // 如果需要前进后退按钮
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev',
                    }
                })
            }
        }
    })
}